package com.honor.games.wg.graphics.actors;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.honor.games.wg.entities.WGBoard;

public class WGBoardActor extends WGActor {

	private float tileSizeWidth = 15;
	private float tileSizeHeight = 7;
	private int nbTilesWidth = 32;
	private int nbTilesHeight = 32;
	private float positionX = 160;
	private float positionY = 188;
	private Texture boardTexture;
	private Texture selectionTexture;
	private float selectionX;
	private float selectionY;
	
	private boolean selected = false;

	public WGBoardActor(String name, WGActorType actorType, float tileSizeWidth, float tileSizeHeight, int nbTilesWidth, int nbTilesHeight,
			float positionX, float positionY) {
		super(name, actorType);
		boardTexture = new Texture(Gdx.files.internal("board.png"));
		selectionTexture = new Texture(Gdx.files.internal("board_cell_selector.png"));
		
		this.tileSizeWidth = tileSizeWidth;
		this.tileSizeHeight = tileSizeHeight;
		this.nbTilesWidth = nbTilesWidth;
		this.nbTilesHeight = nbTilesHeight;

		this.setSize(tileSizeWidth * nbTilesWidth, tileSizeHeight * nbTilesHeight);
		this.setPosition(positionX, positionY);
		this.setZIndex(1);
	}

	public void setSelectedTile(float selectionX, float selectionY) {
		this.selectionX = selectionX;
		this.selectionY = selectionY;
		this.selected = true;
	}
	
	public void unselectTile() {
		this.selected = false;
	}
		
	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		batch.draw(boardTexture, this.getX(), this.getY());

		if (selected) {
			batch.draw(selectionTexture, selectionX, selectionY);
		}
	}
}
